package Day13;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int M = in.nextInt();

        //状态空间记录到达该位置最小的步数
        int[] dp = new int[M+1];
        //初始状态
        dp[N] = 1;

        for (int i = N; i < M; i++) {

            //第i块石板是能跳过来的
            if (dp[i] != 0) {

                //获取当前可以跳跃的步数
                List<Integer> list = getFactors(i );

                //状态空间递推
                for (int j : list) {
                    //跳跃的步数超过目标
                    if (i + j > M) {
                        break;
                    } else {
                        //假如之前没有更优的步数(之前的步数就比加上之后大)
                        if (dp[i+j] > dp[i] + 1 || dp[i+j] == 0) {
                            dp[i+j] = dp[i] + 1;
                        }
                    }
                }

            }

        }

        if (dp[M] == 0) {
            System.out.println(-1);
        } else {
            System.out.println(dp[M] - 1);
        }

    }

    public static List<Integer> getFactors (int n) {

        List<Integer> list = new ArrayList<>();

        //最大约数不会超过n的1/2
        int tmpN = n;
        tmpN /= 2;

        for (int i = 2; i <= tmpN ; i++) {
            if (n % i == 0) {
                list.add(i);
            }
        }

        return list;

    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int n = scanner.nextInt();

        ((Main)null).tyt();

    }
    public static void tyt() {
        System.out.println("test null");
    }
    public static int deal (int m, int n) {

        //创建m~n步数的数组,
        int[] mark = new int[n - m + 1];
        for (int i = 0; i < n - m + 1; i++) {
            mark[i] = Integer.MAX_VALUE;
        }

        for (int i = 0; i < n - m + 1; i++) {

        }

        return 0;

    }
    public static ArrayList<Integer> getInts (int n) {

        ArrayList<Integer> list = new ArrayList<>();

        for (int i = 2; i < n / 2; i++) {
            if (n % i == 0) {
                list.add(i);
            }
        }

        return list;
    }
    public static void main0(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        char[] chars = s.toCharArray();

        int nums = 0;
        Stack<Character> stack = new Stack<>();
        List<String> list = new ArrayList<>();

        StringBuilder tmp = new StringBuilder();
        for (char aChar : chars) {

            //字符为引号
            if (aChar == '"') {

                //前面已经有了引号: 说明一段字符串结束
                if (!stack.empty()) {
                    stack.pop();
                    nums++;
                    list.add(tmp.toString());
                    //tmp重置
                    tmp = new StringBuilder();

                }
                //前面没有引号: 说明一段字符串结束, 另一端字符串开始
                else {

                    if (tmp.length() != 0) {
                        nums++;
                        list.add(tmp.toString());
                        tmp = new StringBuilder();
                    }
                    stack.push(aChar);
                }
                continue;
            }

            //字符为空格
            if (aChar == ' ') {

                //引号间空格
                if (!stack.empty()) {
                    tmp.append(aChar);
                    continue;
                }
                //非引号间空格
                else {
                    if (tmp.length() != 0) {
                        nums++;
                        list.add(tmp.toString());
                        tmp = new StringBuilder();
                    }
                    continue;
                }
            }

            tmp.append(aChar);
        }

        if (tmp.length() != 0) {
            nums++;
            list.add(tmp.toString());
        }

        System.out.println(nums);
        for (int i = 0; i < list.size() - 1; i++) {
            System.out.println(list.get(i));
        }
        System.out.print(list.get(list.size() - 1));

    }

}
